<template>
  <div class="main_sty">
    <div class="top">
      &nbsp;&nbsp;  | &nbsp;&nbsp;
      搜索：<el-input clearable placeholder="单号" suffix-icon="el-icon-search" v-model="input" style="width: 160px"  @change="selectInfo"></el-input>
    </div>
    <div class="separator_sty"></div>
    <el-tabs v-model="activeName"  @tab-click="handleClick" style="padding-left: 10px">
      <el-tab-pane :label="`回款记录`" name="first" >
        <div class="tab">
          <el-table
            ref="multipleTable"
            :data="ctschemsinfo.slice((currentPage2-1)*pageSize2,currentPage2*pageSize2)"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="handleSelectionChange">

            <el-table-column
              prop="customer.cusName"
              label="客户"
              width="180">
              <template slot-scope="scope">
                <el-button type="text" size="small"  @click="mainInfo(scope.row)"> {{scope.row.customer.cusName}}</el-button>
              </template>
            </el-table-column>
            <el-table-column
              prop="ctAmount"
              label="回款金额"
              width="180">
            </el-table-column>
            <el-table-column
              prop="orderInfoByOrderId.orderTotal"
              label="订单金额"
              width="180">
            </el-table-column>
            <el-table-column
              prop="orderInfoByOrderId.orderName"
              label="订单编号"
              width="180">
            </el-table-column>
            <el-table-column
              prop="ctData"
              label="回款日期"
              width="180">
            </el-table-column>

            <el-table-column
              prop="emp.empName"
              label="所有者"
              width="180">
            </el-table-column>

            <el-table-column
              prop=""
              label="操作"
              width="180">
              <template slot-scope="scope">
                <i @click="goOrderInfo(scope.row)" class="el-icon-s-promotion"></i>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <div class="page">
          <el-pagination style="float:right;margin-top: 5px;" :current-page.sync="currentPage2" :page-sizes="[10, 25, 40,100]"
                         :page-size="pageSize2" layout="total, sizes, prev, pager, next, jumper"
                         :total="ctschemsinfo.length"
                         @current-change="changeProSize"
                         @size-change="handleSizeChange2">
          </el-pagination>
        </div>
      </el-tab-pane>
      <el-tab-pane :label="`退款记录`" name="second" @click="opl">
        <div class="tab">
          <el-table
            ref="multipleTable"
            :data="refundList.slice((currentPage2-1)*pageSize2,currentPage2*pageSize2)"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="handleSelectionChange">

            <el-table-column
              prop="customer.cusName"
              label="客户"
              width="180">
            </el-table-column>

            <el-table-column
              prop="orderInfo.orderName"
              label="订单"
              width="150">
            </el-table-column>
            <el-table-column
              prop="returnorder.retuName"
              label="对应的退货单"
              width="150">
            </el-table-column>

            <el-table-column
              prop="refundAmount"
              label="退款金额"
              width="150">
            </el-table-column>

            <el-table-column
              prop="refundState"
              label="状态"
              width="150">
              <template slot-scope="scope">
                <span v-if="scope.row.refundState==0">
                  处理中
                </span>
                <span v-if="scope.row.refundState==1">
                  已完成
                </span>
              </template>
            </el-table-column>

            <el-table-column
              prop="refundTime"
              label="时间"
              width="150">
              <template slot-scope="scope">
                {{scope.row.refundTime | formatDate}}
              </template>
            </el-table-column>


            <el-table-column
              prop="emp.empName"
              label="负责人"
              width="150">
            </el-table-column>

            <el-table-column
              prop=""
              label="操作"
              width="170">
              <template slot-scope="scope">

                  <a>
                  <i class="el-icon-edit"></i>
                  </a>
                   <a>
                  <i class="el-icon-tickets"></i>
                  </a>


              </template>
            </el-table-column>

          </el-table>
        </div>
        <div class="page">
          <el-pagination style="float:right;margin-top: 5px;" :current-page.sync="currentPage2" :page-sizes="[10, 25, 40,100]"
                         :page-size="pageSize2" layout="total, sizes, prev, pager, next, jumper"
                         :total="refundList.length"
                         @current-change="changeProSize"
                         @size-change="handleSizeChange2">
          </el-pagination>
        </div>

      </el-tab-pane>
    </el-tabs>


    <el-dialog title="回款记录" :visible.sync="dialogFormVisible" custom-class="dialog_color" width="65%">
      <hr class="border-t-a"/>
      <el-form :model="ctschemsDeatils" ref="complain"  label-width="100px" label-position="right" style="margin-left: 20px">
        <el-form-item label="对应客户">
          <el-input style="width:655px" v-model="ctschemsDeatils.customerName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="对应订单" >
          <el-input style="width:655px" v-model="ctschemsDeatils.orderName" autocomplete="off"></el-input>
        </el-form-item>
        <el-row>
        <el-col :span="10">
          <el-form-item label="期次" >
            <el-input style="width: 100%" v-model="ctschemsDeatils.period" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10" :push="2">
          <el-form-item label="日期" >
            <el-input style="width: 100%" v-model="ctschemsDeatils.date" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="金额" >
              <el-input style="width: 100%" v-model="ctschemsDeatils.amount" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10" :push="2">
            <el-form-item label="付款方式" >
              <el-input style="width: 100%" v-model="ctschemsDeatils.payment" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="是否开发票" >
              <el-input style="width: 100%" v-model="ctschemsDeatils.invoice  " autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10" :push="2">
            <el-form-item label=所有者 >
              <el-input style="width: 100%" v-model="ctschemsDeatils.userNmae" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <el-drawer
      title="我是标题"
      :visible.sync="drawer"
      :direction="direction"
      :with-header="false"
      size="50%">

      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-row>
              <el-col :span="24">
                <div style="border: 1px solid red ; width: 100%;height: 100px; background-color: #20a0ff"></div>
              </el-col>
            </el-row>
          </div>
        </el-col>
      </el-row>
    </el-drawer>
  </div>
</template>

<script>
  import {amountToStr, formatTimeToStr} from '../assets/format'
  import TemplateVue from './homepage/TemplateVue'

  export default {
    components: {TemplateVue},
    data() {
      return {
        selctInfoFalge:1,
        input:'',//汽车型号搜索
        //回/退款
        ctschemsinfo:[],//回款
        refundList:[],//退款
        dialogFormVisible:false,
        ctschemsDeatils:{
          customerName:"",
          orderName:"",
          period:"",
          date:"",
          amount:"",
          invoice:"",
          payment:"",
          userNmae:""
        },//回款详情
        //退换货
        currentPage2:0,
        pageSize2:10,

        currentPage1:1,//当前页
        pageSizes1:[4, 8, 12],//可选择的页大小
        totalSize1:0,//总页数
        exchangOrderInfo:[],//换货单
        retouerOrderInfo:[],//退货单
        fhuodanInfo:[],//发货单
        activeName: 'first',//卡片名称
        tableDate: [],    //产品信息列表
        exchangeState:false,
        /////////////////////////////////////////////////////////
        category:'',//类型查询
        data2: [],//产品分类数组
        searchPro:'',//添加商品里面的查询
        pcId:0,//类型id
        pbId:0,//品牌id
        ///////////////
        drawer:false,
        direction:'rtl',
        value:'',//汽车品牌搜索
        options:[],//汽车品牌
        productList:[],//产品信息

        colData: [{title: "名称",istrue: true},//动态列
          {title: "型号",istrue: true},],
        colOptions: [], //默认全选
        colSelect: [],


        //分页
        totalSize:0,
        pageSize:0,
        currentPage:1,
        sizes:[10, 15, 20],//分页可改变的页数
      };
    },
    created :function() {
      this.ctschemsEvent(this.input);
      this.refundInfo(this.input);
      //加载产品分类
      this.$axios.get("http://localhost:8088/buInfo/category")
        .then(v=>{
          this.data2=v.data;
        }).catch();

    },
    methods: {
      refundInfo(searchInfo){
          this.$axios.get("http://localhost:8088/erfund_Info",{params:{searchInfo:searchInfo}}).then(v=>{
          this.refundList=v.data;
        }).catch();
      },
      goOrderInfo(scope){
        this.$router.push({path:'demopage', query: {key:scope.orderInfoByOrderId.orderId}})
      },
      mainInfo(row){
        this.ctschemsDeatils.customerName=row.customer.cusName;
        this.ctschemsDeatils.orderName=row.orderInfoByOrderId.orderTheme;
        this.ctschemsDeatils.period=row.ctPeriod;
        this.ctschemsDeatils.date=row.ctData;
        this.ctschemsDeatils.amount=row.ctAmount;
        if(row.invoiceState==0){
          this.ctschemsDeatils.invoice="否"
        }else {
          this.ctschemsDeatils.invoice="是"
        }
        this.ctschemsDeatils.payment=row.termsPayment.termsName;
        this.ctschemsDeatils.userNmae=row.emp.empName;
        this.dialogFormVisible=true;
      },
      handleClick(tab, event) {
        this.input='';
        let tabName=tab.name;
        if(tabName=='first'){
          this.selctInfoFalge=1;
        }
        if(tabName=='second'){
          this.selctInfoFalge=2;
        }
        this.currentPage2=1;
        this.pageSize2=10;
        console.log(tab, event);
      },
      selectInfo(){
        if(this.input!=null){
          this.$message("工共"+this.selctInfoFalge);
          if(this.selctInfoFalge==1){
            this.ctschemsEvent(this.input);
          }
          if(this.selctInfoFalge==2){
            this.refundInfo(this.input);
          }
        }else {

        }
      },

      ctschemsEvent(searchInfo){
        this.$axios.get("http://localhost:8088/all_ctschemsinfo",{params:{searchInfo:searchInfo}}).then(v=>{
          this.ctschemsinfo=v.data;
        }).catch()
      },

      //前端分页
      changeProSize: function (size) {
        this.currentPage2 = size;
        console.log("yy"+this.pageSize)  //每页下拉显示数据
      },
      handleSizeChange2: function(currentPage){
        this.pageSize2 = currentPage;
        console.log("kk"+this.pageNum)  //点击第几页
      },

      ///////////////////////////////////////////////
      //类型加品牌查询 和模糊查询
      handleChange(item) {
        if(this.category !='' ){
          this.pbId=item[0];
          this.pcId=item[1];

        }else{
          this.pbId=0;
          this.pcId=0;
        }
        this.initProduct(this.searchPro,this.pcId,this.pbId);

      },
      //产品列表
      initProduct(searchPro,pcId,pbId){
        this.$axios.get("http://localhost:8088/buInfo/newproduct_info",{
          params:{
            productName:searchPro,
            pcId:pcId,
            pbId:pbId
          }
        }).then(v=>{
          this.productList=v.data;
        }).catch();
      },


      /////6_8久代码

      opl(){
        this.$message("okok")
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      },
      changePage(){},
      handleSizeChange(){},
      goBack(){
        this.$router.go(-1);
      },
    },


    filters: {
      formatDate: function (time) {
        if (time != null && time != "") {
          var date = new Date(time);
          return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
        } else {
          return "";
        }
      },
      amountEvent:function(val){
        return amountToStr(val);
      },


    }
  }

</script>


<style scoped>
  .border-t-a {
    border-top: 1px solid #aaaaaa;
    margin-top: -20px;
    margin-bottom: 30px;
  }
  .tab{
    width: 100%;
    max-height: 370px;
    overflow-y: auto;
  }
  .grid-content {
    border-radius: 4px;
    height: 700px;
  }
  .bg-purple {
    background: #F4F8FB;
  }
  .main_sty{
    border:1px solid #ccc;
    width:100%;
    height: 535px;
    background: white;
    border-radius: 5px;
    box-shadow:#ccc 0px 0px 10px;
    overflow:hidden;
  }
  .table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
  }
  .page{
    float: right;
    padding: 15px 0 20px 0;
  }
  .separator_sty{
    border:1px solid #409eff;
    margin: 0 auto;
  }
  .top{
    padding-left: 10px;
    margin: 3px;
    padding:5px;
  }
</style>
